import request from "@/utils/request";

const Finance_BASE_URL = "/admin/hp/record-rec";
const Finance_Withdrawal_URL = "/admin/pay/approve/list";
const Finance_Charge_URL = "/admin/examine/rec/list";
const Finance_Charge_Examine_URL = "/admin/examine/rec";

const EXPORT_Withdrawal_URL = "/admin/pay/export/approve-list";
const EXPORT_AUDIT_URL = "admin/pay/review/approve";
const Commission_BASE_URL = "/admin/config/commission-list";
const Commission_EDIT_URL = "/admin/config/modify-commission";

const FinanceAPI = {
  /**
   * 获取充值列表
   *
   * @returns 树形表格数据
   */
  List(data: any) {
    return request<any, any>({
      url: `${Finance_BASE_URL}`,
      method: "post",
      data,
    });
  },

  ListAudit(params: any) {
    return request<any, any>({
      url: `${Finance_Charge_URL}?page=${params.pageNum}&limit=${params.pageSize}&markId=${params.keywords}&state=${params.status}&hashVal=${params.hashVal}&currency=${params.currency}`,
      method: "get",
    });
  },

  ListAuditDo(data: any) {
    return request<any, any>({
      url: `${Finance_Charge_Examine_URL}`,
      method: "post",
      data,
    });
  },

  /**
   * 获取提现列表
   *
   * @returns 树形表格数据
   */
  getList(params: Query) {
    if (params.createTime && params.createTime.length > 0) {
      params.startTime = params.createTime[0];
      params.endTime = params.createTime[1];
    } else {
      params.startTime = "";
      params.endTime = "";
    }
    return request<any, any>({
      url: `${Finance_Withdrawal_URL}?page=${params.pageNum}&limit=${params.pageSize}&markId=${params.keywords}&approveState=${params.status}&startTime=${params.startTime}&endTime=${params.endTime}&currency=${params.currency}`,
      method: "get",
    });
  },

  export_excel(data: any) {
    const params = new URLSearchParams();
    const create_at = data.createTime;
    params.append("approveState", data.status);
    params.append("markId", data.keywords);
    params.append("startTime", create_at[0]);
    params.append("endTime", create_at[1]);
    params.append("currency", data.currency);
    return request<any, any>({
      url: `${EXPORT_Withdrawal_URL}?${params.toString()}`,
      method: "get",
    });
  },

  /**
   * 修改
   *
   * @param id ID
   * @param data 表单数据
   * @returns 请求结果
   */
  edit(data: WithdrawalForm) {
    return request({
      url: `${EXPORT_AUDIT_URL}`,
      method: "POST",
      data,
    });
  },

  /**
   * 获取手续费列表
   *
   * @returns 树形表格数据
   */
  getCommissionList() {
    return request<any>({
      url: `${Commission_BASE_URL}`,
      method: "get",
    });
  },

  /**
   * 新增
   *
   * @param data 表单数据
   * @returns 请求结果
   */
  create(data: CommissionForm) {
    return request({
      url: `${Commission_EDIT_URL}`,
      method: "post",
      data,
    });
  },

  /**
   * 修改
   *
   * @param id ID
   * @param data 表单数据
   * @returns 请求结果
   */
  update(data: any) {
    return request({
      url: `${Commission_EDIT_URL}`,
      method: "post",
      data,
    });
  },

  /**
   * 删除
   *
   * @param ids ID，多个以英文逗号(,)分隔
   * @returns 请求结果
   */
  deleteByIds(ids: string) {
    return request({
      url: `${Finance_BASE_URL}/${ids}`,
      method: "delete",
    });
  },
};

export default FinanceAPI;

/** 查询参数 */
export interface Query {
  keywords?: string;
  pageNum: number;
  pageSize: number;
  status: string;
  startTime?: string;
  endTime?: string;
  createTime?: string[];
  currency?: string;
}

/** 充值列表 */
export interface ChargeVO {
  /** 创建时间 */
  createTime?: string;
  /** ID */
  id?: string;
  /** 账号 */
  account?: string;
  /** 订单号 */
  order_no?: string;
  /** 排序 */
  sort?: number;
  /** 充值状态 */
  status?: number;
  /** 充值金额 */
  money?: string;
  /** 头像 */
  avatar?: string;
}

/** 提现审核列表 */
export interface WithdrawalVO {
  /** 创建时间 */
  createTime?: string;
  /** ID */
  id?: string;
  /** 提现时间 */
  auditTime?: string;
  /** 账号 */
  account?: string;
  /** 订单号 */
  order_no?: string;
  /** 排序 */
  sort?: number;
  /** 提现状态 */
  approveState?: number;
  /** 提现金额 */
  money?: string;
  /** 手续费 */
  commission?: string;
  /** 实际到账金额 */
  amount?: string;
  /** 头像 */
  avatar?: string;
  /*银行名称*/
  bank_name?: string;
  /*开户行*/
  bank_address?: string;
  /*银行卡号*/
  bank_number?: string;
  /** 备注 */
  remark?: string;
}

/** 表单类型 */
export interface WithdrawalForm {
  /** ID(新增不填) */
  id?: string;
  /** 审核时间 */
  //auditTime?: string;
  /** 状态(0:未审核；1：已审核)；2：已驳回) */
  approveState?: number;
  remark?: string;
}

/** 手续费类型 */
export interface CommissionVO {
  /** 创建时间 */
  createTime?: string;
  /** ID */
  id?: string;
  /** 名称 */
  name?: string;
  /** 排序 */
  sort?: number;
  /** 费率 */
  rate?: string;
  /** 状态(0:禁用；1：正常) */
  status?: number;
}

/** 表单类型 */
export interface CommissionForm {
  /** ID(新增不填) */
  id?: string;
  /** 名称 */
  chargeFee?: string;
  /** 费率 */
  riseU: string;
  /** 排序 */
  sort?: number;
  /** 状态(0:禁用；1：正常) */
  status?: number;
  tronAddress?: string;
  bnbAddress?: string;
}
